#pragma once

#include"Common.h"
#include"SpendType.h"

namespace Macro
{
	class Supply
	{
	public:
		Supply(Player* player)
			:_used(player->supplyUsed()),
			_total(player->supplyTotal())
		{
		}
		inline void SpendStarted(const SpendType& spendType)
		{
			if(spendType == Lair)
			{
			}
			else
			{
				_used += SupplyRequired(spendType);
				_used -= SupplyRequired(WhatMakes(spendType));
			}
		}
		inline void SpendFinished(const SpendType& spendType)
		{
			if(spendType == Lair)
			{
			}
			else
			{
				_total += SupplyProvided(spendType);
			}
		}
		inline bool AllowBuild(const SpendType& spendType) const
		{
			const int& supplyNeeded(SupplyRequired(spendType));
			return supplyNeeded <= 0 || supplyNeeded <= Remain();
		}

		inline const int Remain() const
		{
			return _total - _used;
		}
		inline const int Used() const
		{
			return _used;
		}
		inline const int Total() const
		{
			return _total;
		}
		//--
		const static int MAX_SUPPLY = 200;
	private:
		int _used;
		int _total;
	};
}